package com.hq.sso.service.impl;

import com.hq.sso.model.User;
import com.hq.sso.service.UserService;
import org.springframework.stereotype.Service;

/**
 * @ClassName UserServiceImpl
 * @Description TODO
 * @Author huangzl
 * @Date 2018/10/17 15:24
 * @Version 1.0
 **/
@Service
public class UserServiceImpl implements UserService {

    @Override
    public User getUser(String userName, String password) {
        if("admin".equals(userName)&&"123456".equals(password)){
            return new User(1,"admin","123456");
        }
        return null;
    }

    public User findAccountForToken(String token){
        String[] arr = token.split("|");
        if("1".equals(arr[0])){
            return new User(1,"admin","123456");
        }
        return null;
    }

    @Override
    public String getTokenForAccount(User account) {
        // 真实场景中，该值应该是账号Id拼接时间戳后加密生成。
        return String.format("%s",account.getId());
    }
}